package com.onegene.pdf.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;

import java.util.function.Consumer;

/**
 * @author: laoliangliang
 * @description: 耗时计算工具
 * @create: 2020/7/9 10:35
 **/
@Slf4j
public class StopWatchUtil {

    public static void calculate(String desc, Consumer<String> consumer) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        consumer.accept(desc);
        stopWatch.stop();
        log.info("{}耗时{}秒", desc, stopWatch.getTotalTimeSeconds());
    }

}
